package com.soft.javase.ch06.date;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/25
 */
public class DateCalculation {
    public static void main(String[] args) {
        // 计算 "2014-5-25" 到 "2012-12-28" 中间有多少天
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d");
        LocalDate startDate = LocalDate.parse("2012-12-28", formatter);
        LocalDate endDate = LocalDate.parse("2014-5-25", formatter);
        long daysBetween = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate);
        System.out.println("'2014-5-25' 到 '2012-12-28' 中间有 " + daysBetween + " 天。");

        // 计算距离当前时间 500 天后的日期和时间、星期
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime futureDateTime = now.plusDays(500);
        DayOfWeek futureDayOfWeek = futureDateTime.getDayOfWeek();
        System.out.println("距离当前时间 500 天后的日期和时间是：" + futureDateTime);
        System.out.println("距离当前时间 500 天后是：" + futureDayOfWeek);

        // 假设出生当天是 2000-01-01，计算这天是星期几
        LocalDate birthDate = LocalDate.of(2002, 12, 29);
        DayOfWeek birthDayOfWeek = birthDate.getDayOfWeek();
        System.out.println("出生当天是：" + birthDayOfWeek);
    }
}
